$(function(){
	$("form#editRoomForm").validate({
		rules: {
			name: 'required',
			type: 'required',
			category: 'required',
			visible: 'required'
		},
		messages: {
			name: {
				required: "请输入房间名称"
			},
			type: {
				required: "请选择房间类型"
			},
			category: {
				required: "请选择房间分类"
			},
			visible: {
				required: "请选择房间可见类型"
			}
		},
		submitHandler: function(form){
			var btn = $('button:submit', form);
			btn.button('loading');
			$.ajax({
				type: 'post',
				url: $(form).attr('action'),
				data: $(form).serialize(),
				success: function(res){
					btn.button('reset');
					if(res.status == 'ok'){
						success(res.message);
					}else{
						error(res.message);
					}
				}
			});
		}
	});
	
	$('input:radio[name=type]').on('click', function(){
		if($(this).val() == 1){
			$('#roomAddress').addClass('hidden');
			$('#recordUrl').addClass('hidden');
		}else if($(this).val() == 2){
			$('#recordUrl').removeClass('hidden');
			$('#roomAddress').addClass('hidden');
		}else if($(this).val() == 4){
			$('#roomAddress').removeClass('hidden');
			$('#recordUrl').addClass('hidden');
		}
	});
});